class StudentModel:
    def __init__(self, score=None, name=None, age=None, sid=None):
        self.name = name
        self.age = age
        self.score = score
        self.sid = sid
    def __str__(self):
        return f"{self.name}的编号是{self.sid},得分为{self.score},年龄为{self.age}"
    def __eq__(self, other):
        return  self.sid==other.sid

class StudentView:
    def __init__(self):
        self.__controller = StudentController()
    def main(self):
        while True:
            view.showMenu()
            view.select_Menu()

    def showMenu(self):
        print("1.录入学生信息")
        print("2.显示学生信息")
        print("3.删除学生信息")
        print("4.修改学生信息")

    def select_Menu(self):
        item = input("请输入1~4选项:")
        if item == "1":
            self.__input_student_info()
        elif item == "2":
            self.__show_student()
        elif item == "3":
            self.__delete_student()
        elif item == "4":
            self.__modify__student()

    def __input_student_info(self):
        """
        录入学生信息
        """
        stu = StudentModel()
        stu.name = input("请输入学生姓名:")
        stu.age = int(input("请输入学生年龄:"))
        stu.score = int(input("请输入学生分数:"))
        self.__controller.add_Student(stu)

    def __show_student(self):
        for item in self.__controller.list_student:
                print(item)

    def __delete_student(self):
        ssid = int(input("请输入要删除的学生编号:"))
        if self.__controller.remove_student(ssid):
            print("删除成功")
        else:
            print("删除失败")

    def __modify__student(self):
        stu = StudentModel()
        stu.sid = int(input("请输入学生编号:"))
        stu.name = input("请输入学生姓名:")
        stu.age = int(input("请输入学生年龄:"))
        stu.score = int(input("请输入学生分数:"))
        if self.__controller.update_student(stu):
            print("修改成功")
        else:
            print("修改失败")



class StudentController:
    start_id = 1001

    @classmethod
    def set_student_id(cls, new_stu):
        new_stu.sid = cls.start_id
        cls.start_id += 1

    def __init__(self):
        self.__list_student = []
    @property
    def list_student(self):
        return self.__list_student

    def add_Student(self, new_stu):
        StudentController.set_student_id(new_stu)
        self.list_student.append(new_stu)

    def remove_student(self, ssid):
        # for i in range(len(self.list_student)):
        #     if self.list_student[i].sid == ssid:
        #         del self.list_student[i]
        #         return True
        # return False
        stu=StudentModel(sid=ssid)
        if stu in self.__list_student:
            self.__list_student.remove(stu)
            return True
        else:
            return False

    def update_student(self, stu):
        for item in self.list_student:
            if stu.sid == item.sid:
                item.name = stu.name
                item.age = stu.age
                item.score = stu.score
                # item.__dict__=stu.__dict__
                return True
        return False


view = StudentView()
view.main()